package bookoperation;

import book.Book;
import book.BookList;

import java.util.Scanner;

public class DelBook implements  IOperation{
    @Override
    public void show(BookList bookList) {
        Scanner scanner = new Scanner(System.in);
        System.out.print("请输入你要删除的书籍:>");
        String name = scanner.nextLine();
        int size = bookList.getUseSize();
        int flag = -1;

        for (int i = 0; i < size; i++) {
            Book ret = bookList.getBooks(i);
            if (name.equals(ret.getBookName())) {
                flag = i;
            }
        }
        if (flag == -1) {
            System.out.println("没有此书");
        }
        for (int i = flag; i < size-1; i++) {
            Book ret = bookList.getBooks(i);
            int tmp = flag+1;
            bookList.setBooks(tmp,ret);
        }
        bookList.setUseSize(size-1);
        bookList.setBooks(size-1,null);
        System.out.println("删除成功");
    }
}
